package api

import (
	"django_blog_gin/internal/dto"
	"django_blog_gin/internal/svc"
	"django_blog_gin/internal/utils"
	"net/http"

	"github.com/gin-gonic/gin"
)

type checkController struct {
	svcCtx *svc.ServiceContext
}

func NewCheckController(svcCtx *svc.ServiceContext) gin.HandlerFunc {
	controller := &checkController{
		svcCtx: svcCtx,
	}
	return controller.check
}

func (c *checkController) check(ctx *gin.Context) {
	var req dto.CheckReq

	if !utils.ValidateJsonBody(ctx, &req) {
		return
	}

	tokenMap, err := utils.ParseJwtToken(req.Token)
	if err != nil {
		utils.ResponseError(ctx, http.StatusBadRequest, err.Error())
		return
	}

	utils.ResponseSuccess(ctx, tokenMap, "ok")
}
